package com.cloudpivot.project.crmprojectnew.configuration.SerializerConfig;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;


/**
 * 联系人转换器
 * 自定义序列化转换器
 */
public class ContactSerializer extends JsonSerializer  {
    @Override
    public void serialize(Object o, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {

        if(o instanceof Boolean){
            if((Boolean)o==true){
                jsonGenerator.writeNumber(1);
            }else{
                jsonGenerator.writeNumber(0);
            }
        }else if(o instanceof Integer){
            if((Integer)o==1){
                jsonGenerator.writeBoolean(true);
            }else{
                jsonGenerator.writeBoolean(false);
            }
        }else{
            jsonGenerator.writeObject(null);
        }
    }
}
